# person_info = {
#     "name": "Alex",
#     "age": 30,
#     "country": "USA",
#     "language": ["English", "Spanish"],
#     "is_student": False
# }
#
# # 1.打印`person_info` 字典的`name` 值。
# print('name:',person_info['name'])
#
# # 2.. 修改`age` 的值为 31。
# person_info['age'] = 31
# print('修改后的age：',person_info['age'])
#
# # 3.向字典中添加一个新的键值对 `height": 175`。
# person_info.update({"height":"175"})
# print("新增height：",person_info['height'])
#
# # 4.删除字典中的 `is_student"` 键及其值。
# person_info.pop("is_student")
# try:
#     print("验证是否删除is_s:", person_info('is_student'))
# except:
#     print("已删除")
#
# # 5.使用循环遍历字典，打印所有的键和值。
# for i in person_info.items():
#     print("键值对：",i)
#
# # 6.检查字典中是否有 `email"` 这个键，如果没有，添加 `email": "alex@example.com"`。
# if 'email' not in person_info:
#     person_info.update({'email':"alex@example.com"})
#     print('验证email',person_info['email'])
#
# # 7.将`language` 的值改为只包含 `English"`。
# # person_info['language'] = 'English'
# # print('验证是否更改成功:',person_info['language'])
#
# # 8.获取并打印字典中`language` 列表的长度。
# list = person_info['language']
# print("language列表长度",len(list))
# # 9.向`language` 列表中添加一种新语言 `French"`。
# list.append("French")
# person_info['language'] = list
# print("验证french是否添加成功:",person_info['language'])
# # 10.循环插入新的键值对到字典：将 ` hobby'` + 数字 作为键，相应的 ` hobby'` + 数字值 作为值，数字从1至3
# for i in range(1,4):
#     key = f"hobby{i}"
#     value = f"hobby{i}"
#     person_info.update({key:value})
# for i in person_info.items():
#     print("10题",i)

#param 进阶

def writeEmployee(dict):
    for i in dict:
        print(i, dict[i])


employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    },
    # 更多员工数据...
}
# 1. 新增一个员工的信息到`employees`字典中。
employee102 = {
        "name": "Steve",
        "age": 25,
        "gender": "Male",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [40000, 45000, 50000]
    }
employees.update({102:employee102})
# writeEmployee(employees)

# 2. 删除一个指定的员工的信息。
# no = int(input("输入要删除人员的工号:"))
# employees.pop(no)
# writeEmployee(employees)

# 3. 更新员工101的年龄至31。
employee101 = employees[101]
employee101.update({"age":31})
print(employees[101]['age'])

# 4. 增加员工101薪资历史中的最新薪资至95000。
salary101 = employee101['salary_history']
salary101.append(95000)
employee101.update({"salary_history": salary101})
print(employees[101]['salary_history'])

# 5. 计算员工101的平均薪资。
a = 1
for salary in salary101:
    salary+=salary
    a+=1
print("总薪资：",salary)
print("平均薪资",salary/a)

# 6. 找出所有年龄大于25岁的员工的姓名和ID。
for i in employees:
    if employees[i]['age'] > 25:
        print("ID:",i,"姓名:",employees[i]['name'])

# 7. 对`employees`中的每个员工，添加'bonus'键至其字典中，其中值是最新薪资的10%。
for i in employees:
    max_salary = max(employees[i]['salary_history'])
    employees[i].update({"bonus":max_salary*0.1})
    print(employees[i])
# 8. 将员工101的职位更新为"Senior Data Scientist"。
employee101.update({"position": "Senior Data Scientist"})
print(employee101['position'])

# 9. 从员工的信息中移除`gender`键。
for i in employees:
    employees[i].pop("gender")
    print(employees[i])

# 10. 创建一个新的嵌套字典，该字典仅包含员工的`name`和`position`。
new_employee={
    103:{
        'name':'Mike',
        'position':'boss'
    }
}
